package com.euc.springbootframework.auth;

import com.euc.springbootframework.auth.service.TokenAuthenticationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component(value = "LogoutHandler")
public class MyLogoutHandler implements LogoutHandler {

    @Autowired
    TokenAuthenticationService tokenAuthenticationService;

    @Override
    public void logout(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) {
        SecurityContextHolder.clearContext();
        tokenAuthenticationService.removeAuthentication(httpServletRequest,httpServletResponse);
    }
}
